package einoagent

import (
	"context"

	"github.com/cloudwego/eino/compose"
	"github.com/cloudwego/eino/flow/agent/react"
)

// newLambda1 component initialization function of node 'ReactAgent' in graph 'EinoAgent'
func newLambda1(ctx context.Context) (lba *compose.Lambda, err error) {
	// TODO Modify component configuration here.

	//1.创建配置
	config := &react.AgentConfig{
		MaxStep:            25,
		ToolReturnDirectly: map[string]struct{}{}}

	chatModelIns11, err := newChatModel(ctx)
	if err != nil {
		return nil, err
	}
	//1.1配置模型
	config.Model = chatModelIns11
	//1.2得到工具
	tools, err := GetTools(ctx)
	if err != nil {
		return nil, err
	}
	//1.3配置工具
	config.ToolsConfig.Tools = tools

	//2.创建react模型
	ins, err := react.NewAgent(ctx, config)
	if err != nil {
		return nil, err
	}

	//3.创建lba
	lba, err = compose.AnyLambda(ins.Generate, ins.Stream, nil, nil)
	if err != nil {
		return nil, err
	}
	return lba, nil
}
